package com.dt.dubai.core.xml;

import ch.qos.logback.core.joran.spi.XMLUtil;
import com.dt.dubai.core.xml.User;
import com.dt.dubai.core.xml.XmlUtil;

import java.util.Date;

public class TestXmlObject {
    public static void main(String[] args) {
        User user = new User(1, "Steven", "@sun123", new Date(), 1000.0);
        // 将对象转换成string类型的xml
        String str = XmlUtil.convertToXml(user);
        System.out.println("---将String类型的xml转换成对象 Start---");
        User userTest = (User) XmlUtil.convertXmlStrToObject(User.class, str);
        System.out.println(userTest);
        System.out.println("---将String类型的xml转换成对象 End---");
       /* List<Computer> list = new ArrayList<Computer>();
        list.add(new Computer("xxxMMeedd", "asus", new Date(), 4455.5));
        list.add(new Computer("lenvoXx", "lenvo", new Date(), 4999));
        user.setComputers(list);*/
        String path = "E:\\workspace1\\dt-mall-admin\\src\\main\\java\\com\\dt\\dubai\\core\\xml\\boy.xml";
        System.out.println("---将对象转换成File类型的xml Start---");
        XmlUtil.convertToXml(user, path);

        System.out.println("---将对象转换成File类型的xml End---");
        System.out.println();

        System.out.println("---将File类型的xml转换成对象 Start---");
        User user2 = (User) XmlUtil.convertXmlFileToObject(User.class, path);
        System.out.println(user2);
        System.out.println("---将File类型的xml转换成对象 End---");
  }
}